package com.cssy.xxkj.basic.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.byd.acegiext.domain.User;
import com.cssy.xxkj.basic.dao.BasicSubjectsDAO;
import com.cssy.xxkj.basic.entity.BasicSubjectsDO;
import com.cssy.xxkj.basic.service.IBasicSubjectsService;
import com.plat.exception.SyBaseException;
import com.plat.helper.SearchConditions;
import com.plat.helper.SearchResult;
import com.plat.util.IDCodeTypeUtil;


@Service("basicSubjectsService")
public class BasicSubjectsServiceImpl implements IBasicSubjectsService{

	
	@Resource(name="basicSubjectsDAO")	
	private BasicSubjectsDAO basicSubjectsDAO;
	
	
	@Override
	public SearchResult findListByExample(SearchConditions scs)
			throws SyBaseException {
		SearchResult rs=new SearchResult(scs);
		List<BasicSubjectsDO>  list=basicSubjectsDAO.find(scs);
		rs.setRecordCount(basicSubjectsDAO.count(scs));
		rs.setResults(list);
		return rs;
	}

	@Override
	public Integer delete(String id, User user) throws SyBaseException {
		return basicSubjectsDAO.deleteBasicSubjectsDOByPrimaryKey(id);
	}

	@Override
	public Integer update(BasicSubjectsDO t, User user) throws SyBaseException {
		t.setBizModifyName(user.getName());
		t.setBizModifyDate(new Date());
		t.setBizVersionMark(t.getBizVersion());
		t.setBizVersion(t.getBizVersion()+1);
		return basicSubjectsDAO.updateBasicSubjectsDO(t);
	}

	@Override
	public BasicSubjectsDO save(BasicSubjectsDO t, User user)
			throws SyBaseException {
		String id  = IDCodeTypeUtil.getId();
		t.setId(id);
		t.setBizCreatorDate(new Date());
		t.setBizCreatorName(user.getName());
		t.setBizVersion(1);
		basicSubjectsDAO.insertBasicSubjectsDO(t);
		return t;
	}

	@Override
	public BasicSubjectsDO findListById(String id) throws SyBaseException {
		return basicSubjectsDAO.findBasicSubjectsDOByPrimaryKey(id);
	}

	@Override
	public Integer deleteBizRemoved(String id) throws SyBaseException {
		return basicSubjectsDAO.deleteBizRemoved(id);
	}
}
